package com.chixing.day08_interface;

import java.util.Comparator;

public class Product implements Comparator<Product> {
    private String proName;
    private int proSale;
    private float proPrice;

    public Product(String proName, int proSale, float proPrice) {
        this.proName = proName;
        this.proSale = proSale;
        this.proPrice = proPrice;
    }

    public Product() {
    }

    //两个商品比较先后顺序
    @Override
    public int compare(Product o1, Product o2) {
//        if(o1.getProSale()-o2.proSale == 0) {
//            return (int) (o1.getProPrice() - o2.getProPrice());
//        }
//        return (int) (o1.getProSale()-o2.getProSale());

//        return (o1.getProSale()-o2.getProSale()>0)?
//                (int) (o1.getProSale()-o2.getProSale()) :
//                (int) (o1.getProPrice() - o2.getProPrice());

        if (o1.getProSale() != o2.getProSale())
            return o1.getProSale()-o2.getProSale();
        else if (o2.getProPrice() != o2.getProPrice())
            return (int) (o1.getProPrice()-o2.getProPrice());
        else
            return o1.getProName().compareTo(o2.getProName());
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public int getProSale() {
        return proSale;
    }

    public void setProSale(int proSale) {
        this.proSale = proSale;
    }

    public float getProPrice() {
        return proPrice;
    }

    public void setProPrice(float proPrice) {
        this.proPrice = proPrice;
    }


    @Override
    public String toString() {
        return "Product{" +
                "proName='" + proName + '\'' +
                ", proSale=" + proSale +
                ", proPrice=" + proPrice +
                '}';
    }
}
